home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
pyxmpp
/
expdict.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
2KB
|
98 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__revision__ = '$Id: expdict.py 600 2005-08-19 10:45:03Z jajcus $'
__docformat__ = 'restructuredtext en'
import time
import threading
class ExpiringDictionary(dict):
__slots__ = [
'_timeouts',
'_default_timeout',
'_lock']
def __init__(self, default_timeout = 300):
dict.__init__(self)
self._timeouts = { }
self._default_timeout = default_timeout
self._lock = threading.RLock()
def __delitem__(self, key):
self._lock.acquire()
try:
del self._timeouts[key]
return dict.__delitem__(self, key)
finally:
self._lock.release()
def __getitem__(self, key):
self._lock.acquire()
try:
self._expire_item(key)
return dict.__getitem__(self, key)
finally:
self._lock.release()
def __setitem__(self, key, value):
return self.set_item(key, value)
def set_item(self, key, value, timeout = None, timeout_callback = None):
self._lock.acquire()
try:
if not timeout:
timeout = self._default_timeout
self._timeouts[key] = (time.time() + timeout, timeout_callback)
return dict.__setitem__(self, key, value)
finally:
self._lock.release()
def expire(self):
self._lock.acquire()
try:
for k in self._timeouts.keys():
self._expire_item(k)
finally:
self._lock.release()
def _expire_item(self, key):
(timeout, callback) = self._timeouts[key]
if timeout <= time.time():
del self[key]
if callback:
try:
callback(key, dict.__getitem__(self, key))
except TypeError:
try:
callback(key)
except TypeError:
callback()
except:
None<EXCEPTION MATCH>TypeError
None<EXCEPTION MATCH>TypeError
None<EXCEPTION MATCH>TypeError